package com.powernobug.service.impl;

import com.powernobug.bean.vo.data.DashboardData;
import com.powernobug.mapper.MarketGoodsMapper;
import com.powernobug.mapper.MarketGoodsProductMapper;
import com.powernobug.mapper.MarketOrderMapper;
import com.powernobug.mapper.MarketUserMapper;
import com.powernobug.service.AdminDashboardService;
import com.powernobug.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-20
 * @Description:
 */
public class AdminDashboardServiceImpl implements AdminDashboardService {
    private static SqlSession tempSession;

    @Override
    public DashboardData statistic() {
        tempSession = MyBatisUtil.getSqlSession();
        int goodsTotal = tempSession.getMapper(MarketGoodsMapper.class).countTotalRecord();
        int userTotal = tempSession.getMapper(MarketUserMapper.class).countTotalRecord();
        int productTotal = tempSession.getMapper(MarketGoodsProductMapper.class).countTotalRecord();
        int orderTotal = tempSession.getMapper(MarketOrderMapper.class).countTotalRecord();
        MyBatisUtil.releaseSqlSession(tempSession);

        return DashboardData.builder()
                .goodsTotal(goodsTotal)
                .userTotal(userTotal)
                .productTotal(productTotal)
                .orderTotal(orderTotal)
                .build();
    }
}
